import request, { all } from '@/utils/request'

/**
 * 数据列表
 * @param params
 * @returns AxiosPromise
 */
export function paginate(params) {
  return request({
    url: '/group/paginate',
    method: 'get',
    params: params
  })
}

/**
 * 详细数据
 * @param id
 * @param callback
 */
export function info(id, callback) {
  const url = [
    request.get('/menu/lists?format=tree')
  ]
  if (id) {
    url.push(request.get('/group/info/' + id))
  }
  all(url, function(res) {
    if (res !== false) {
      callback(res)
    }
  })
}

/**
 * 保存数据
 * @param params
 * @param id
 * @returns AxiosPromise
 */
export function save(params, id = null) {
  return request({
    url: '/group/' + (id ? 'update/' + id : 'store'),
    method: 'post',
    data: params
  })
}

/**
 * 删除数据
 * @param id
 * @returns AxiosPromise
 */
export function destroy(id) {
  return request({
    url: '/group/destroy/' + id,
    method: 'delete'
  })
}
